package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.qf.mapper.DtsGoodsSpecificationMapper;
import com.qf.pojo.DtsGoodsSpecification;
import com.qf.service.DtsGoodsSpecificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class DtsGoodsSpecificationServiceImpl implements DtsGoodsSpecificationService {
    @Autowired
    DtsGoodsSpecificationMapper specificationMapper;

    @Override
    public void deleteByGoodsId(Integer id) {
        LambdaQueryWrapper<DtsGoodsSpecification> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DtsGoodsSpecification::getGoodsId, id);
        specificationMapper.delete(wrapper);
    }

    @Override
    public void insert(DtsGoodsSpecification specification) {
        specification.setAddTime(new Date());
        specification.setUpdateTime(new Date());
        specification.setDeleted(false);


        specificationMapper.insert(specification);
    }

    @Override
    public void updateByGoodsId(Integer id) {
        LambdaUpdateWrapper<DtsGoodsSpecification> wrapper = new LambdaUpdateWrapper();
        wrapper.eq(DtsGoodsSpecification::getGoodsId, id);

        DtsGoodsSpecification specification = new DtsGoodsSpecification();
        specification.setDeleted(true);
        specificationMapper.update(specification, wrapper);
    }
}
